package com.stefanhermann.graphicstest;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;

public class GraphicsTestActivity extends Activity implements OnTouchListener {
	/** Called when the activity is first created. */
	MyGraphicsView myGraphicsView;
	float tempX1, tempY1, tempX2, tempY2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		myGraphicsView = new MyGraphicsView(this);
		myGraphicsView.setOnTouchListener(this);
		setContentView(myGraphicsView);

	}

	public boolean onTouch(View v, MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			tempX1=event.getX();
			tempY1=event.getY();
			myGraphicsView.moveX = event.getX();
			myGraphicsView.moveY = event.getY();
			break;
		case MotionEvent.ACTION_UP:
			tempX2=event.getX();
			tempY2=event.getY();
			myGraphicsView.moveX = 0;
			myGraphicsView.moveY = 0;
			myGraphicsView.getTouchInput(tempX1, tempY1, tempX2, tempY2);
			break;
		case MotionEvent.ACTION_MOVE:
			if(myGraphicsView.selLine != null)
				myGraphicsView.moveLine(event.getX(),event.getY());
			if(myGraphicsView.mode == 1)
				myGraphicsView.createLine(tempX1,tempY1,event.getX(),event.getY());
		}
		
		return true;
	}
}